package Thread.New.等待与唤醒;

public class ChiHuo extends Thread{
    private BaoZi bz;
    public ChiHuo(BaoZi baoZi){
        this.bz = baoZi;
    }

    @Override
    public void run() {
        while(true){
            synchronized (bz){
                if(!bz.flag){
                    try {
                        bz.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //唤醒之后就开始吃包子了
                System.out.println("正在吃包子,吃"+bz.pi+bz.xian+"包子");
                bz.flag = false;
                bz.notify();
                //唤醒包子铺
                System.out.println("吃完了,快去做包子");
                System.out.println("--------------------");
            }
        }
    }
}
